package movie.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import movie.entity.Comment;
import movie.service.CommentService;

@Controller
public class CommentCotroller {
@Autowired
private CommentService commentService;
@RequestMapping(value = "/comment", method = RequestMethod.GET)
public String get(Model model) {
	return "comments/comment";
}

@RequestMapping(value = "/comment", method = RequestMethod.POST)
public String post(String movieName,Model model,HttpServletRequest request) {
	model.addAttribute("movieName", movieName);
	List<Comment> comments=commentService.findComment(movieName);
	System.out.println(comments);
	model.addAttribute("comments", comments);
	HttpSession session = request.getSession();
	session.setAttribute("movieName", movieName);
	return "comments/commentlist";
}
}
